package example06;
import java.awt.*;
import javax.swing.*;
import net.sf.jeppers.grid.*;

/**
 * @author <a href="mailto:grom@capsicumcorp.com">Cameron Zemek</a>
 */
public class BooleanCellRenderer implements GridCellRenderer {
	private JCheckBox checkBox = new JCheckBox();
	
	public BooleanCellRenderer() {
		checkBox.setHorizontalAlignment(SwingConstants.CENTER);
		checkBox.setBackground(Color.WHITE);
	}
	
	public Component getRendererComponent(
			int row, int column, 
			Object value, 
			CellStyle style, 
			boolean isSelected, 
			boolean hasFocus, 
			JGrid grid) {
        boolean selected = false;
        if (value instanceof Boolean) {
            selected = ((Boolean) value).booleanValue();
        } else if (value instanceof String) {
            selected = value.equals("true");
        }
        checkBox.setSelected(selected);
		return checkBox;
	}

}
